var c = require('../../lib/common.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    session: null,
    switchstatus: 'open',
    switchfont: '（开启状态中......）',
    usersendpet: null,
    checkedtrue:true,
    checkedfalse:false,
    topname: '宠物领养小站',
    prepage: 1
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    //获得session值
    var userinfo = wx.getStorageSync('userinfo');
    console.log(userinfo.id);
    wx.request({
      url: 'https://www.cwlyz.com/wx/User/mysendoutpetlist',
      data: {
        id: userinfo.id,
      },
      success: function(res) {
        console.log(res);
        that.setData({
          usersendpet: res.data.data,
          // type: res.data.data[0].sy_type
        });
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  switchChanges: function(res) {
    console.log(111222);
    var usersendpet = this.data.usersendpet;
    var sy_id = res.currentTarget.dataset.id;
    var type = res.currentTarget.dataset.type;
    var index = res.currentTarget.dataset.index;
    var settype = (type == 1) ? 2 : 1;
    var setusersendpet = 'usersendpet['+index+'].sy_type';
    var that = this;
    var status = (type == 1) ? '设置已经被送养' : '设置继续送养';
    wx.showModal({
      title: '状态设置',
      content: status,
      success: function (sm) {
        wx.showLoading({
          title: '设置中...',
        })
        if (sm.confirm) {
          wx.request({
            url: 'https://www.cwlyz.com/wx/User/mysendoutpetset',
            data: {
              sy_id: sy_id
            },
            success: function (res) {
              wx.hideLoading();
              c.pan('设置成功!');
              that.setData({
                [setusersendpet]: settype, type: settype
              })
            }
          })
        }else{
          wx.hideLoading();
          that.setData({
            [setusersendpet]: type
          })
        }
      }
    })
  },
  clicktopinfo: function(res) {
    wx.showModal({
      title: '置顶操作',
      content: '确定要设置置顶吗？',
      success: function(sm) {
        if (sm.confirm) {
          // 用户点击了确定 可以调用删除方法了
          var sy_id = res.currentTarget.dataset.id;
          wx.request({
            url: 'https://www.cwlyz.com/wx/User/mysendoutpetup',
            data: {
              sy_id: sy_id
            },
            success: function(res) {
              c.pan('设置成功!')
            }
          })
        }
      }
    })
    return;
  },
  applylist: function (e) {
    var sy_id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/applyList/applyList?id=' + sy_id,
    })
  }
})